﻿using System;
using System.ComponentModel;
using System.Configuration;

namespace Mbs.Configuration
{
    public class ComponentElement : ConfigurationElement
    {
        public struct Constance
        {
            public const string Id = "id";
            public const string Service = "service";
            public const string Implement = "implement";
            public const string IsSingleton = "singleton";
            public const string Immediate = "immediate";
        }

        [ConfigurationProperty(Constance.Id)]
        public string Id
        {
            get { return (string)this[Constance.Id]; }
            set { this[Constance.Id] = value; }
        }

        [ConfigurationProperty(Constance.Service, IsRequired = true)]
        [TypeConverter(typeof(TypeNameConverter))]
        public Type Service
        {
            get { return (Type)this[Constance.Service]; }
            set
            {
                this[Constance.Service] = value;
            }
        }

        [ConfigurationProperty(Constance.Implement, IsRequired = true)]
        [TypeConverter(typeof(TypeNameConverter))]
        public Type Implement
        {
            get { return (Type)this[Constance.Implement]; }
            set
            {
                this[Constance.Implement] = value;
            }
        }

        [ConfigurationProperty(Constance.IsSingleton)]
        public bool IsSingleton
        {
            get { return (bool)this[Constance.IsSingleton]; }
            set { this[Constance.IsSingleton] = value; }
        }

        [ConfigurationProperty(Constance.Immediate, DefaultValue = true)]
        public bool Immediate
        {
            get { return (bool)this[Constance.Immediate]; }
            set { this[Constance.Immediate] = value; }
        }
    }
}
